package io.renren.modules.workplan.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.workplan.entity.WorkplanEntity;
import io.renren.modules.workplan.service.WorkplanService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
@RestController
@RequestMapping("workplan/workplan")
public class WorkplanController {
    @Autowired
    private WorkplanService workplanService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("workplan:workplan:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = workplanService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{wpNo}")
    @RequiresPermissions("workplan:workplan:info")
    public R info(@PathVariable("wpNo") Integer wpNo){
		WorkplanEntity workplan = workplanService.getById(wpNo);

        return R.ok().put("workplan", workplan);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("workplan:workplan:save")
    public R save(@RequestBody WorkplanEntity workplan){
		workplanService.save(workplan);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("workplan:workplan:update")
    public R update(@RequestBody WorkplanEntity workplan){
		workplanService.updateById(workplan);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("workplan:workplan:delete")
    public R delete(@RequestBody Integer[] wpNos){
		workplanService.removeByIds(Arrays.asList(wpNos));

        return R.ok();
    }

}
